//
//  SHTabPageDemoViewController.swift
//  RxSwiftDemo2019_03_31
//
//  Created by bebull on 2021/12/27.
//  Copyright © 2021 远平. All rights reserved.
//

import UIKit
import QMUIKit
//QMUICommonViewController,
class SHTabPageDemoViewController: UIViewController, UIGestureRecognizerDelegate {//
    
    private lazy var tabLayout: YXTabLayout = {
        let layout = YXTabLayout.default()
        layout.titleColor = UIColor.qmui_color(withHexString: "#878D9A") ?? .red
        layout.titleSelectedColor = UIColor.qmui_color(withHexString: "#1D252C") ?? .red
        layout.titleFont = UIFont.systemFont(ofSize: 16)
        layout.titleSelectedFont = UIFont.systemFont(ofSize: 16, weight: .semibold)
        
        layout.tabWidth = 50.0
        layout.leftAlign = true
        layout.lrMargin = 0
        layout.tabMargin = 0
        layout.lineColor = .clear
        return layout
    }()
    
    lazy var tabView: YXTabView = {
        let tabView = YXTabView(frame: CGRect(x: 0, y: 0, width: 160, height: 30), with: self.tabLayout)
        tabView.backgroundColor = .white
        tabView.delegate = self as YXTabViewDelegate
        tabView.layer.borderWidth = 0
        tabView.titles = ["自选", "市场", "资讯"]
        tabView.pageView = self.pageView
        return tabView
    }()
    
    
    private lazy var pageView: YXPageView = {
        let view = YXPageView()
        view.contentView.isScrollEnabled = true
        view.parentViewController = self
        view.backgroundColor = .clear
        view.contentView.backgroundColor = .clear
        view.viewControllers = [SHOptionalViewController(), SHMarketViewController(), SHNewsHomeViewController()]
        return view
    }()
    
    private let kTabHeight: CGFloat = 48
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.titleView = self.tabView
                
        tabView.reloadData()
//        navigationController?.interactivePopGestureRecognizer?.delegate = self
        
        view.addSubview(self.pageView)
        if let controller = self.navigationController, let recognizer = controller.interactivePopGestureRecognizer {
            pageView.contentView.panGestureRecognizer.require(toFail: recognizer)
        }
        

        pageView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalToSuperview().offset(YXConstant.navBarHeight())
        }
    }
    
//    override func shouldPopViewController(byBackButtonOrPopGesture byPopGesture: Bool) -> Bool {
//        return true
//    }
}

extension SHTabPageDemoViewController: YXTabViewDelegate {
    
    func tabView(_ tabView: YXTabView, didSelectedItemAt index: UInt, withScrolling scrolling: Bool) {
        ///
    }
    
}
